﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

/*********************************************************
 * 命名空间 MDT.LifeSewagePlatform.Repository
 * 接口名称 AlaramRuleRepository
 * 开发人员：-nhy
 * 创建时间：2022/3/31 11:35:43
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace MDT.LifeSewagePlatform.Repository
{
    public class AlaramRuleRepository: HandleBaseRepository<AlaramRuleEntity>,IAlaramRuleRepository
    {
        public AlaramRuleRepository()
        {

        }

        public IQueryable<AlaramRuleView> GetAlaramRules(Expression<Func<AlaramRuleView,bool>>expression)
        {
            var query = from rule in _dbContext.AlaramRules.AsNoTracking()
                        join rtype in _dbContext.Details.AsNoTracking().Where(rt => rt.MainID == (int)eDictionary.alaramType) on rule.AlaramType equals rtype.RowID
                        join compare in _dbContext.Details.AsNoTracking().Where(rt => rt.MainID == (int)eDictionary.comparePattern) on rule.ComparePattern equals compare.RowID
                        select new AlaramRuleView
                        {
                            Id=rule.ID,
                            AlaramTypeName=rtype.RowName,
                            ComparePattern=rule.ComparePattern,
                            Standard=rule.Standard,
                            AlarmaType=rule.AlaramType,
                            ComparePatternDesc=compare.RowName,
                            DescriptionInfo=rule.DescriptionInfo,
                            DisplayName=rule.DisplayName,
                        };

            return query.Where(expression);
        }
    }
}
